package com.yuandengta.linebasefrmaedecoder;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @Author:Hardy
 * @QQ:2937270766
 * @官网：http://www.yuandengta.com
 */
public class ServerHandler extends ChannelInboundHandlerAdapter {
    int counter = 0;
    private static final String MESSAGE = "It greatly simplifies and streamlines network programming such as TCP and UDP socket server._$";

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            System.out.println("接收客户端msg:[" + msg + "]");
            ByteBuf echo = Unpooled.copiedBuffer(MESSAGE.getBytes());
            ctx.writeAndFlush(echo);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
